package com.project.webpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.webpage.dto.LineAppealedDto;
import com.project.webpage.dto.LineAppealedParam;
import com.project.webpage.dto.SearchByMonthParam;
import com.project.webpage.entity.LineAppealed;
import com.project.webpage.mapper.LineAppealedMapper;
import com.project.webpage.service.LineAppealedService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LineAppealedServiceImpl implements LineAppealedService {

    @Resource
    private LineAppealedMapper lineAppealedMapper;

    @Override
    @DS("secondary")
    public List<LineAppealedDto> getListForPage(LineAppealedParam param) {
        return lineAppealedMapper.selectListByUid(param);
    }

    @Override
    @DS("secondary")
    public LineAppealedDto getDistrict(SearchByMonthParam param) {
        return lineAppealedMapper.selectDistrict(param);
    }

    @Override
    @DS("secondary")
    public List<LineAppealed> getById(Integer id) {
        Example example = new Example(LineAppealed.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("id", id);
        return lineAppealedMapper.selectByExample(example);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void insert(LineAppealed entity) {
        lineAppealedMapper.insertSelective(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void update(LineAppealed entity, Integer idBefore) {
        Example example = new Example(LineAppealed.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("id", idBefore);
        lineAppealedMapper.updateByExampleSelective(entity, example);
    }
}
